//
//  MarkerModel.swift
//  baidu_map_plugin
//
//  Created by CTI on 2021/2/1.
//

import UIKit

class MarkerModel: NSObject {
    var latitude:Double = 0.0
    var longitude: Double = 0.0
    var text: String = ""
    var id: String = ""
    var isSelect: Bool = false
    
    static func fromJson(jsonData:[String: Any]) -> MarkerModel{
        let model = MarkerModel()
        model.latitude = jsonData["latitude"] as! Double
        model.longitude = jsonData["longitude"] as! Double
        model.text = jsonData["text"] as! String
        model.id = jsonData["id"] as! String
        model.isSelect = jsonData["isSelect"] as! Bool
        return model
    }
    
    func toJson() -> String {
        var  jsonData: [String: Any] = [:]
        jsonData["latitude"] = latitude
        jsonData["longitude"] = longitude
        jsonData["text"] = text
        jsonData["id"] = id
        jsonData["isSelect"] = isSelect
        
        let data = try? JSONSerialization.data(withJSONObject: jsonData, options: JSONSerialization.WritingOptions.init(rawValue: 0))
//        let data = try? JSONSerialization.data(withJSONObject: jsonData, options: JSONSerialization.WritingOptions.prettyPrinted )
        let jsonStr = String(data: data!, encoding: .utf8)
        return jsonStr ?? ""
    }
}
